package com.tuo51.evaluate.repositories.impl;


import com.tuo51.evaluate.repositories.EvaluateRecordNativeRepository;
import com.tuo51.evaluate.vo.IDCountDateVO;
import com.matt.repository.base.BaseNativeSqlRepository;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class EvaluateRecordNativeRepositoryImpl extends BaseNativeSqlRepository implements EvaluateRecordNativeRepository {

    @Override
    public Map<String, IDCountDateVO> findEvaluatePBSummaryByChildrenIds(List<String> childrenIds){
        if(childrenIds == null || childrenIds.size() == 0){
            return new HashMap<>();
        }

        String sql = "select childrenId as 'id', count(*) as 'count', max(created) as 'date' " +
                "from tb_evaluate_record " +
                "where childrenId in :1 and deleted=false and finished = true " +
                "group by childrenId ";

        List params = new ArrayList();
        params.add(childrenIds);

        List<IDCountDateVO> items = sqlObjectList(sql, params, IDCountDateVO.class);

        return IDCountDateVO.toMap(items);
    }
}
